package com.yuqian.JavaSe.leetcode.easy;
/**
 * 反转一个字符串里面的原因字母
 * @author yuqian
 *
 */
public class ReverseVowelsofaString {
	 public String reverseVowels(String s) {
         if(s!=null&&!"".equals(s)){
	        	char[] sChars=  s.toCharArray();
	        	int left =0;
	        	int right = sChars.length-1;
	        	while(left<right){
	        	    //交换
	        	    if(isVowel(sChars[left])&&isVowel(sChars[right])){
	        	        char tmpe = sChars[left];
	        	        sChars[left] = sChars[right];
	        	        sChars[right] = tmpe;
	        	        left++;
	        	        right--;
	        	        continue;
	        	    }
	        	    if(!isVowel(sChars[left])) left++;
	        	    if(!isVowel(sChars[right])) right--;
	        	}
	        
	        	return new String(sChars);
	        }
	        return s;
    }
    public boolean isVowel(char c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
    }
    
    public static void main(String[] args) {
    	ReverseVowelsofaString rs = new ReverseVowelsofaString();
    	System.out.println(rs.reverseVowels("hello"));
	}
}
